<?php
/**
 * Copyright 2013 Thomas McRae and Karl Minnich
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * fermdbObject.php
 *
 * Abstract object definition of objects that could possibly be contained
 * in the fermentation database.
 */
abstract class fermdbObject
{
    /**
     * Constructor
     *
     * Leverages variable-length argument strings to construct the handle to
     * the object.  The _only_ passed object should be a mysqli resource.
     */
    function __construct()
    {
        if (func_num_args() > 0)
            $this->_db = func_get_arg(0);
    }
    /**
     * Gets the primary key (database / URL ID) for the object.
     * 
     * @return integer
     */
    public function getLink()
    {
        return $this->pkid;
    }
    /**
     * Gets the last updated date/time
     * @param string $format Format string
     * @return integer|string
     */
    public function getLastUpdateTime($format = "")
    {
        if ($format == "") return $this->lastUpdated;
        return date($format, $this->lastUpdated);
    }
    /**
     * Gets the parent object of this one.
     * @return resource|NULL
     */
    public function getParent()
    {
        return $this->parent;
    }
    /**
     * save the current record -- children must define this!
     */
    abstract public function save();
    /**
     * database handle
     * @var resource
     */
    protected $_db;
    /**
     * generic primary key identifier resource
     * @var integer
     */
    protected $pkid;
    /**
     * generic timestamp for the last updated date/time (from UNIX EPOCH)
     * @var integer
     */
    protected $lastUpdated;
    /**
     * link back to the parent object
     * @var resource
     */
    protected $parent = NULL;
}
?>